Building Games with Flutter by Paul Teale
Author:Paul Teale
Language: eng
Format: epub
Publisher: Packt
Published: 2022-11-15T00:00:00+00:00
Figure 7.3 â Using the terrain images to make a larger map
Notice in Figure 7.3 that a much larger water area was created by reusing the smaller tile images to build something much bigger.
The Tiled tool makes creating tile maps very easy, including tools such as image editing, which allow you to draw with tiles onto the map however you like. You can export maps from Tiled in a variety of formats, but XML and JSON are the most common.
Tiled is a tool that is easy to get started with but also has advanced features beyond the scope of this book, so we won't go into any more detail about it here. Instead, we will provide the premade tile maps for use in our game, so that you can use them directly, but I do recommend spending some time with Tiled once you want to create tile maps for your own games.
When you export a map from Tiled, it has a lot of information about the map and tile size, but the map data section is represented as a 2D array, which could look something like this:
[
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 2, 2, 2, 2, 2, 2, 1],
[1, 2, 3, 3, 3, 3, 2, 1],
[1, 2, 2, 2, 2, 2, 2, 1],
[1, 1, 1, 1, 1, 1, 1, 1]
]
The 2D array in the preceding code block is eight tiles wide and five tiles high. 1 in the array could represent the tile ID for some mountains, 2 might represent a path, and 3 might be water. So, in this example, the map has a path around a lake in the center of the map, with mountains around the outer edges.
Inside a game, we would load this data and iterate over the array and draw each visible tile based on its tile ID. We will draw the tiles starting at the top left, 0,0, and then go through the tile data line by line, drawing each tile in turn.
Now that we have had an introduction to tile maps, we will add our own to the game in the next section.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12520)
Hello! Python by Anthony Briggs(9867)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9757)
The Mikado Method by Ola Ellnestam Daniel Brolund(9747)
Dependency Injection in .NET by Mark Seemann(9293)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8258)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7741)
Grails in Action by Glen Smith Peter Ledbrook(7667)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7517)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6743)
Microservices with Go by Alexander Shuiskov(6510)
Practical Design Patterns for Java Developers by Miroslav Wengner(6408)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6386)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6378)
Angular Projects - Third Edition by Aristeidis Bampakos(5765)
The Art of Crafting User Stories by The Art of Crafting User Stories(5296)
NetSuite for Consultants - Second Edition by Peter Ries(5241)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5058)
Kotlin in Action by Dmitry Jemerov(5019)
